package com.vzaar.examples;

import com.vzaar.VideoDetails;
import com.vzaar.VideoDetailsRequest;
import com.vzaar.Vzaar;
import com.vzaar.VzaarException;

/**
 * Example showing the video details command.
 * 
 * @author Marc G. Smith
 */
public class VideoDetailsExample 
{
	///////////////////////////////////////////////////////////////////////////

	public static void main(String[] args) {
		try {
			ParameterHelper helper = new ParameterHelper(args);
			args = helper.getRemainingArgs();
			if(args.length != 1) {
				printUsage();
				System.exit(1);
				return;
			}

			Vzaar vzaar = helper.createVzaar();
			VideoDetails video = vzaar.getVideoDetails(
				VideoDetailsRequest.fullDetails(Integer.parseInt(args[0])));
			System.out.println("Type:              " + video.getType());
			System.out.println("Title:             " + video.getTitle());
			System.out.println("Description:       " + video.getDescription());
			System.out.println("Width:             " + video.getHeight() + " pixels");
			System.out.println("Height:            " + video.getWidth() + " pixels");
			System.out.println("Video Status ID:   " + video.getVideoStatusId());
			System.out.println("Borderless:        " + (video.isBorderless() ? "Yes" : "No"));
			System.out.println("Duration:          " + video.getDuration() + " seconds");
			System.out.println("Author Name:       " + video.getAuthorName());
			System.out.println("Author Account:    " + video.getAuthorAccount());
			System.out.println("Provider Name:     " + video.getProviderName());
			System.out.println("Provider URL:      " + video.getProviderUrl());
			System.out.println("Thumbnail URL:     " + video.getThumbnailUrl());
			System.out.println("Thumbnail Width:   " + video.getThumbnailWidth() + " pixels");
			System.out.println("Thumnail Height:   " + video.getThumbnailHeight() + " pixels");
			System.out.println("Framegrab URL:     " + video.getFramegrabUrl());
			System.out.println("Framegrab Width:   " + video.getFramegrabWidth() + " pixels");
			System.out.println("Framegrab Height:  " + video.getFramegrabHeight() + " pixels");
			System.out.println("Embed html:        " + video.getHtml());
		}
		catch(VzaarException e) {
			System.err.println("Error: " + e.getMessage());
			System.exit(2);
		}
		catch(ArrayIndexOutOfBoundsException e) {
			printUsage();
			System.exit(1);
		}
		catch(NumberFormatException e) {
			printUsage();
			System.exit(1);
		}
	}
	
	///////////////////////////////////////////////////////////////////////////

	private static final  void printUsage() {
		System.out.println("Usage: vzaar-video " +
			ParameterHelper.getCommonCommandLineArgs() + " <videoId>\n");
		System.out.println("Params:");
		System.out.println("   <videoId>           " +
			"The video number of the video");
		System.out.println(ParameterHelper.getCommonCommandLineHelp());
	}
	
	///////////////////////////////////////////////////////////////////////////
}
